<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS --><!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">
    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css"/>
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css"/>
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">

</head>
<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
    <!-- SIDEBAR -->
    <div id="sidebar" class="sidebar">
        <div class="sidebar-menu nav-collapse">

            <!-- SIDEBAR MENU -->
            <ul>
            </ul>
        </div>


    </div>
    <!-- /SIDEBAR -->
    <div id="main-content">
        <!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
        <div class="modal fade" id="send_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" style="width: 800px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">订单发货</h4>
                    </div>
                    <div class="modal-body" style='height: 500px;'>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>物流公司：</label>
                            <div class="col-md-4">
                                <select id="express_select" class="col-md-12 select2-offscreen" tabindex="-1">
                                    <option value='STO'>申通快递</option>
                                    <option value='ZTO'>中通快递</option>
                                    <option value='YTO'>圆通速递</option>
                                    <option value='SF'>顺丰速运</option>
                                    <option value='YD'>韵达速递</option>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>物流单号：</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="expressCode" placeholder="请输入物流单号" maxlength="20"/>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商品种类数：</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="goodAmount" placeholder="请输入发货种类" maxlength="20">
                            </div>
                            <div class="col-md-5">
                                （跟红包、返利等逻辑有关系,请认真填写。）
                            </div>

                        </div>
                        <div class="form-group" style="height: auto">
                            <label class="control-label col-md-3"><span class="required">*</span>商品明细：</label>
                            <div class='send-detail' style="float: right;width: 568px;"></div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
        <div class="modal fade" id="logistics_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">导出物流</h4>
                    </div>
                    <div class="modal-body">
                        <form action="../../admin/order/exportLogisticsCode.do">
                            <div class="form-group">
                                <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>物流公司：</label>
                                <div class="col-md-4">
                                    <select id="express_select" name="expCode" class="col-md-12 select2-offscreen" tabindex="-1">
                                        <option value='STO'>申通快递</option>
                                        <option value='ZTO'>中通快递</option>
                                        <option value='YTO'>圆通速递</option>
                                        <option value='SF'>顺丰速运</option>
                                        <option value='YD'>韵达速递</option>

                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>物流单号：</label>
                                <div class="col-md-4">
                                    <textarea type="text" class="form-control" cols="5" rows=3 name="logisticsCode" placeholder="请输入物流单号,多个换行"></textarea>

                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="update_exp_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">修改运费</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>原运费：</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" readonly="readonly" name="oldExpressPrice" maxlength="20"/>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>新运费：</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" name="newExpressPrice" placeholder="请输入运费" maxlength="20"/>

                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="update_user_remark_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">修改用户备注</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group" style="margin-bottom:0px">
                            <label class="control-label col-md-3">订单编号：</label>
                            <div class="col-md-4 orderId">

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;">用户备注：</label>
                            <div class="col-md-8">
                                <textarea rows="2" cols="20" class="form-control col-md-12" name="userRemark"
                                          placeholder="请输入用户备注"></textarea>

                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="update_address_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">修改收货地址</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group" style="margin-bottom:0px">
                            <label class="control-label col-md-3">订单编号：</label>
                            <div class="col-md-4 orderId">

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3" style="line-height:34px;">收货地址：</label>
                            <div class="col-md-8">
                                <textarea rows="2" cols="20" class="form-control col-md-12" name="address"
                                          placeholder="格式:收货人，电话，省，市，区，详细地址(英文逗号分隔)"></textarea>

                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="box-qrcode" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="width:250px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">扫码支付</h4>
                    </div>
                    <div class="modal-body">
                        <img width="200" height="200"/>
                    </div>

                </div>
            </div>
        </div>
        <div class="modal fade" id="exportSku_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">导出商品订单</h4>
                    </div>
                    <div class="modal-body">
                        <form action="../../admin/order/exportOrderByProductId.do">
                            <div class="form-group">
                                <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商品ID：</label>
                                <div class="col-md-4">
                                    <textarea class="form-control" name="productIds" placeholder="请输入商品Id,多个请用英文逗号分隔"
                                              style="width: 335px; height: 98px;"/></textarea>
                                </div>
                            </div>

                        </form>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="updateSupplier_Config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">更新商家</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商品ID：</label>
                            <div class="col-md-4">
                                <textarea class="form-control" name="productIds" placeholder="请输入商品Id,多个请用英文逗号分隔"
                                          style="width: 335px; height: 98px;"/></textarea>
                            </div>
                        </div>
                        <div class="row">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商家变更为：</label>
                            <div class="col-md-4">
                                <select id="supplier_select" name="supplierId" class="col-md-12 select2-offscreen" tabindex="-1">
                                </select>
                            </div>
                        </div>
                        <!--<div class="row">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>提示：</label>
                            <div class="col-md-4">
                            <span>只能将商家变更为非壹果</span>
                            </div>
                        </div>-->
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="pushSupplierOrderConfig" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">推送商家订单</h4>
                    </div>
                    <div class="modal-body">

                        <div class="row">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商家：</label>
                            <div class="col-md-4">
                                <select id="push_supplier_select" name="supplierId" class="col-md-12 select2-offscreen" tabindex="-1">
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>提示：</label>
                            <div class="col-md-6">
                                <span><font color="red">会将所有该商家未发货订单推送到旺店通,<br/>
                                壹果商家请不要使用该功能</font></span>
                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div id="content" class="col-lg-12">
                    <!-- PAGE HEADER-->
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="page-header">
                                <!-- STYLER -->

                                <!-- /STYLER -->
                                <!-- BREADCRUMBS -->
                                <ul class="breadcrumb">
                                    <li>
                                        <i class="fa fa-home"></i>
                                        <a href="index.html">首页</a>
                                    </li>
                                    <li>
                                        <a href="#">营销管理</a>
                                    </li>
                                    <li>优惠劵</li>
                                </ul>
                                <!-- /BREADCRUMBS -->

                            </div>
                        </div>
                    </div>
                    <!-- /PAGE HEADER -->
                    <!-- FORMS QUERY-->
                    <div class="row">
                        <div class="col-md-12">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="box border primary">
                                        <div class="box-title">
                                            <h4><i class="fa fa-bars"></i>查询条件</h4>
                                        </div>
                                        <div class="box-body big" style="padding:10px;">
                                            <form class="form-horizontal" role="form" id="form_Order" action="../../admin/order/exportOrder.do">
                                                <div class="form-group mrg-bt10">
                                                    <label class="col-sm-1 control-label" style="width: auto">订单编号：</label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control" name="q" placeholder="输入关键字">
                                                    </div>

                                                    <label class="col-sm-1 control-label" for="e1" style="width: 108px">状态：</label>
                                                    <div class="col-sm-2">
                                                        <select id="status_select" name="orderStatus" class="col-md-12 select2-offscreen" tabindex="-1">
                                                            <option value=-1>选择状态</option>
                                                            <option value="WaitingPay">待付款</option>
                                                            <option value="WaitingCheck">待审核</option>
                                                            <option value="WaitingSend">待发货</option>
                                                            <option value="WaitingSign">待签收</option>
                                                            <option value="TradeSuccess">交易成功</option>
                                                            <option value="TradeClosed">交易关闭</option>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-1 control-label" style="width: auto">下单日期：</label>
                                                    <div class="col-sm-4" style="display:inline-flex;margin-left:-10px">
                                                        <div class="col-sm-2" style="width:130px">
                                                            <input type="text" name="startDate" class="form-control bootstrap-datepicker">
                                                        </div>
                                                        <div style="width: 20px">至</div>
                                                        <div class="float-left" style="width:130px">
                                                            <input type="text" name="endDate" class="form-control bootstrap-datepicker">
                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="form-group mrg-bt10">
                                                    <label class="col-sm-1 control-label" style="width: 96px">用户名：</label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control" name="userName" placeholder="输入关键字">
                                                    </div>
                                                    <label class="col-sm-1 control-label" style="width: auto">收货人电话：</label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control" name="telPhone" placeholder="输入关键字">
                                                    </div>

                                                    <label class="col-sm-2 control-label" style="width: auto">source值：</label>
                                                    <div class="col-sm-3" style="width: 160px">
                                                        <input type="text" class="form-control" name="sourceCode" placeholder="请输入source值">
                                                    </div>
                                                    <div class="col-sm-2" style="width: 120px">
                                                        <input type="checkbox" checked="checked" name="validOrder"><span style='margin-left:10px'>有效订单</span>
                                                    </div>
                                                </div>
                                                <div class="form-group mrg-bt10">
                                                    <label class="col-sm-1 control-label" for="e1" style="width: auto">订单来源：</label>
                                                    <div class="col-sm-2">
                                                        <select id="platform_select" name="appType" class="col-md-12 select2-offscreen" tabindex="-1">
                                                            <option value="">全部</option>
                                                            <option value="WeChat">M站</option>
                                                            <option value="Small">小程序</option>
                                                            <option value="Android">Android</option>
                                                            <option value="Ios">IOS</option>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-1 control-label" for="e1" style="width: auto">订单类型：</label>
                                                    <div class="col-sm-2" style="margin-left: 12px">
                                                        <select id="order_type_select" name="orderType" class="col-md-12 select2-offscreen" tabindex="-1">
                                                            <option value="">全部</option>
                                                            <option value="Ordinary">普通订单</option>
                                                            <option value="GroupBuying">拼团订单</option>
                                                            <option value="KanJia">砍价订单</option>
                                                            <option value="CardCoupon">红包订单</option>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-2 control-label" style="width: auto">产品名称：</label>
                                                    <div class="col-sm-3" style="width: 160px">
                                                        <input type="text" class="form-control" name="productName" placeholder="请输入关键字">
                                                    </div>
                                                    <!-- <div class="col-sm-2" style="width: 120px">
                                                      <input type="checkbox"  name="supplierId"><span style='margin-left:10px'>第三方商家</span>
                                                    </div> -->
                                                    <div class="col-sm-1" style='padding-right:200px'>
                                                        <a class="btn btn-primary search">查询</a>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                    <!-- /FORMS QUERY -->
                    <div class="row" style="height: 30px;">
                        <div class="col-md-12">
                            <div class="box ">
                                <a href="javaScript:;" class="btn btn-success export" url="../../admin/order/exportOrder.do">
                                    <i class="fa  fa-plus-square-o"></i> 导出订单
                                </a>
                                <a href="javaScript:;" class="btn btn-warning exportLogistics" url="../../admin/order/exportOrderLogistics.do">
                                    <i class="fa  fa-plus-square-o"></i> 导出物流单号
                                </a>

                                <a href="javaScript:;" class="btn btn-warning batchSubmit">
                                    <i class="fa  fa-plus-square-o"></i> 批量同步订单
                                </a>
                                <a href="no_send_order_list.html" class="btn btn-success">
                                    <i class="fa  fa-plus-square-o"></i>未发货统计
                                </a>
                                <a href="javaScript:;" class="btn btn-warning updateSupplier">
                                    <i class="fa  fa-plus-square-o"></i>更新商家
                                </a>
                                <a href="javaScript:;" class="btn btn-primary exportSkuOrder">
                                    <i class="fa  fa-plus-square-o"></i>导出销售
                                </a>
                                <a href="out_order_import.html" class="btn btn-primary">
                                    <i class="fa  fa-plus-square-o"></i>导入外部订单
                                </a>
                                <a href="javaScript:;" class="btn btn-warning pushSupplierOrder">
                                    <i class="fa  fa-plus-square-o"></i>推送商家订单
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <!-- TABLES -->
                        <div class="col-md-12">
                            <!-- BOX -->
                            <div class="box border primary">
                                <div class="box-title">
                                    <h4><i class="fa fa-table"></i>订单数：<span id="total"></span>条 </h4>

                                </div>
                                <div class="box-body">
                                    <table id="db_Order_list" style="table-layout:fixed;word-break:break-all;word-wrap:break-word" cellpadding="0"
                                           cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

                                    </table>
                                </div>
                            </div>
                            <!-- /BOX -->
                        </div>
                    </div>
                    <!-- /TABLES -->


                    <div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
                    </div>
                </div><!-- /CONTENT-->
            </div>
        </div>
    </div>
</section>
<!--/PAGE -->
<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- JQUERY -->
<script src="../../js/jquery/jquery-2.0.3.min.js"></script>

<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>
<script src="../../js/common.js"></script>
<script>
    var Order = function () {
        var $mainDataTable = null;
        var sendOrder = function () {

            var pid = $(this).attr("pid");
            $("#express_select").select2();
            getOrderDetail(pid);
            $("#send_config").modal("show");
            $(".bt-save").unbind("click").click(function () {
                var code = $("[name=expressCode]").val();
                var goodAmount = $("[name=goodAmount]").val();
                var detailIds = '';
                $(".send-detail").find('[name=sendDetail]').each(function () {
                    if ($(this).prop("checked")) {
                        detailIds += this.id + ",";
                    }
                });
                if (detailIds == '') {
                    $.alert("请选择发货商品。")
                }


                if (goodAmount == "") {
                    $("#send_config").find("[name=goodAmount]").parents(".form-group").addClass("has-error");
                    return false;
                }
                if (code.trim() == "") {
                    $("#send_config").find(".form-group:eq(1)").addClass("has-error");
                    return false;
                }
                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/sendOrder.do",
                    data: {
                        orderId: pid,
                        expressCompany: $("#express_select option:selected").text(),
                        expressCode: code,
                        logisticsCode: $("#express_select").val(),
                        goodAmount: $("[name=goodAmount]").val(),
                        detailIds: detailIds.substring(0, detailIds.length - 1)
                    },
                    async: true,
                    success: function (result) {
                        $.alert("订单发货成功");
                        $("#send_config").modal("hide");
                        $("[name=expressCode]").val('');
                        searchOrder();

                    }

                });

            });
        };
        var getOrderDetail = function (orderId) {
            $.ajax({
                type: "get",
                url: App.getContextPath() + "admin/order/orderDetail.do",
                data: {orderId: orderId},
                async: true,
                success: function (result) {
                    var str = "";
                    $.each(result.orderDetail, function (index, item) {
                        if (!item.sendMark && item.refundStatus == "NoRefund")
                            str += "<div class=\"col-md-6\"> <input type=\"checkbox\" name='sendDetail' checked  id = '" + item.id + "'><span  >" + item.productName + "</span></div>";

                    })
                    $('.send-detail').html(str);
                }

            });
        }
        var loadSupplier = function (callback) {
            $.ajax({
                type: "get",
                url: App.getContextPath()
                    + "admin/store/searchSupplierList.do",
                async: true,
                success: function (result) {
                    if (result != null) {
                        var data = eval(result);
                        var option = "<option value=''>选择商家</option>";
                        $.each(data, function (index, item) {
                            option += "<option value='" + item.id + "'>"
                                + item.supplierName + "</option>";
                        });
                        callback(option)

                    }
                }
            });
        };
        var completeOrder = function () {
            var pid = $(this).attr("pid");
            $.confirm("你确认订单已经签收?", function () {
                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/completeOrder.do",
                    data: {id: pid},
                    async: true,
                    success: function (result) {
                        $.alert("订单签收成功");
                        searchOrder();

                    }

                });

            });
        };
        var syncOrder = function () {
            var orderId = $(this).attr("pid");
            $.confirm("你确认需要同步订单吗?", function () {
                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/syncOrder.do",
                    data: {orderId: orderId},
                    async: true,
                    success: function (result) {
                        if (result.type == 'error') {
                            $.alert(result.content);
                        } else {
                            $.alert(result.content);
                        }
                        searchOrder();

                    }

                });

            });
        };
        var updateExpPrice = function () {
            var pid = $(this).attr("pid");
            var oldExpressPrice = $(this).attr("expressPrice");
            $("#update_exp_config").modal("show");
            $("[name=oldExpressPrice]").val(oldExpressPrice);
            $(".bt-save").unbind("click").click(function () {
                var newExpressPrice = $("[name=newExpressPrice]").val();
                if (newExpressPrice.trim() == "") {
                    $("#update_exp_config").find(".form-group:eq(1)").addClass("has-error");
                    return;
                } else {
                    $.ajax({
                        type: "get",
                        url: App.getContextPath() + "admin/order/updateExpressPrice.do",
                        data: {orderId: pid, expressPrice: newExpressPrice},
                        async: true,
                        success: function (result) {
                            $.alert("修改成功");
                            $("#update_exp_config").modal("hide");
                            $("[name=newExpressPrice]").val('');
                            $("[name=oldExpressPrice]").val('');
                            searchOrder();

                        }

                    });


                }
            });
        };

        var payOrder = function () {
            var pid = $(this).attr("orderId");
            var totalPrice = $(this).attr("totalPrice");
            $.ajax({
                type: "get",
                url: App.getContextPath() + "admin/order/payOrder.do",
                data: {orderId: pid, totalPrice: totalPrice},
                async: true,
                success: function (result) {

                    searchOrder();

                }

            });
            /* var state=pid+"-"+totalPrice+"-WeChat";
               $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/qrPayOrder.do",
                    data:{state:state},
                    async: true,
                    success: function(result) {

                        console.log(result);
                        $("#box-qrcode").find("img").attr("src",result.content);
                        $("#box-qrcode").modal("show");
                        }

                }); */

        }

        var searchOrder = function () {

            var startDate = $("input[name=startDate]").val();
            var endDate = $("input[name=endDate]").val();
            var q = $("input[name=q]").val();
            var status = $("#status_select").val();
            var platform = $("#platform_select").val();
            var url = App.getContextPath() + "admin/order/searchOrder.do?q=" + q + "&userName=" + $("[name=userName]").val() + "&telPhone=" + $("[name=telPhone]").val()
                + "&validOrder=" + $("[name=validOrder]").prop("checked") + "&appType=" + platform + "&sourceCode=" + $("[name=sourceCode]").val() + "&orderType=" + $("[name=orderType]").val()
                + "&productName=" + $("#form_Order").find("[name=productName]").val();
            if (status != null && status != -1)
                url += "&orderStatus=" + status;
            if (q == "") {
                if (startDate != "")
                    url += "&startDate=" + startDate;
                if (endDate != "")
                    url += "&endDate=" + $.dateAdd(endDate);
            }
            if ($("[name=supplierId]").prop("checked"))
                url += "&isOtherSupplier=1";

            if ($mainDataTable) {
                $mainDataTable.api().ajax.url(url).load();
                return;
            }
            var dtSetting = $.dataTableSetting({
                "ajaxSource": url,
                "serverSide": true,
                "bFilter": false,// 去掉搜索框
                "bLengthChange": true,// 每页显示数量
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "iDisplayLength": 25,

                "bSort": false,
                "aoColumns": [{
                    "mDataProp": "orderId",
                    "sTitle": "订单编号",
                    "width": "10%",
                    "class": "orderId",
                    "render": function (data, type, row) {
                        var s1 = "", s = "", u = ""
                        if (row.platformNo == "M001") s1 = "<span style='color:red'>店</span>";
                        if (row.orderType == "GroupBuying") {
                            u = '<span>' + row.orderId + "</span><img width='16' height='16' src='../../img/pintuan.png' alt=''/>";

                        } else if (row.orderType == "KanJia")
                            u = '<span>' + row.orderId + "</span><img width='16' height='16' src='../../img/kan.png' alt=''/>";
                        else
                            u = row.orderId;
                        if (row.sendType == "SupplierSend" && row.orderStatus != 'WaitingPay')
                            s = "<a style='color:red' target='_blank' href='../product/new_supply.html?id=" + row.supplierId + "&flag=1'>商:" + row.supplierId + "</a>";
                        return s1 + u + s;


                    }
                },
                    {
                        "mDataProp": "wdtOrderCode",
                        "sTitle": "旺店通订单",
                        "width": "9%"
                    }, {
                        "mDataProp": "userId",
                        "sTitle": "用户ID",
                        "width": "0%",
                        "class": "hide"
                    }, {
                        "sTitle": "用户名",
                        "mDataProp": "userName",
                        "width": "10%",
                        "class": "userName"
                    }, {
                        "sTitle": "source值",
                        "mDataProp": "source_Code",
                        "width": "10%"
                    }, {
                        "sTitle": "收货人",
                        "mDataProp": "receiver",
                        "width": "10%"
                    }
                    , {
                        "sTitle": "实付金额 ",
                        "width": "8%",
                        "render": function (data, type, row) {
                            return format_thousands(row.totalPrice);
                        }
                    }
                    , {

                        "sTitle": "订单状态",
                        "width": "8%",
                        "render": function (data, type, row) {
                            var str = "";
                            switch (row.orderStatus) {
                                case "TradeClosed":
                                    str = "交易关闭";
                                    break;
                                case "WaitingPay":
                                    str = "待付款";
                                    break;
                                case "WaitingCheck":
                                    str = "待审核";
                                    break;
                                case "WaitingSend":
                                    str = "待发货";
                                    break;
                                case "WaitingSign":
                                    str = "待签收";
                                    break;
                                case "TradeSuccess":
                                    str = "交易成功";
                                    break;
                            }
                            return str;
                        }

                    }, {

                        "sTitle": "下单时间",
                        "width": "8%",
                        "render": function (data, type, row) {
                            return $.getLocalTime(row.createTime);
                        }
                    }
                    , {

                        "sTitle": "退换货",
                        "width": "7%",
                        "render": function (data, type, row) {
                            if (row.returnOrderId != 0) {
                                return "<a target=_blank href='../returnorder/return_order_list.html?orderid=" + row.orderId + "'>是</a>";
                            }
                            return "";
                        }
                    }, {
                        "sTitle": "操作",
                        "width": "15%",
                        "render": function (data, type, row) {
                            var str = "<a target='_blank' class='btn btn-warning btn-xs btn-width' style='width:60px;margin-left:0px;margin-right:5px;margin-top:2px;' href='order_detail.html?id=" + row.orderId + "'><i class='fa fa-arrow-circle-o-up'></i>详情</a>";


                            if ((row.orderType != 'CardCoupon' && (row.orderStatus == "WaitingSend" && row.wdtOrderCode == null) || (row.orderStatus == "WaitingSend" && new Date().getTime() - row.paidTime > 1 * 24 * 60 * 60 * 1000)))
                                str += "<a class='btn btn-danger btn-xs bt_sync btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' pid='" + row.orderId + "'><i class='fa fa-pencil-square-o'></i>同步订单</a>";
                            if ((row.orderStatus == "WaitingPay"))
                                str += "<a class='btn btn-danger btn-xs bt_update_exp_price btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' pid='" + row.orderId + "' expressPrice='" + row.expressPrice + "'><i class='fa fa-pencil-square-o'></i>改运费</a>";
                            if ((row.orderStatus == "WaitingSign" || row.orderStatus == "TradeSuccess") && row.orderType != 'CardCoupon')
                                str += "<a class='btn btn-primary btn-xs  btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;width:60px' href='../returnorderoff/add.html?orderId=" + row.orderId + "&returnType=Return' pid='" + row.orderId + "'><i class='fa fa-arrow-circle-o-up'></i>退货</a>";
                            if (window.location.origin != "http://houtai.yiigoo.com") {
                                if (row.orderStatus == "WaitingSign")
                                    str += "<a class='btn btn-success btn-xs bt_complete btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' pid='" + row.id + "'><i class='fa fa-pencil-square-o'></i>订单完成</a>";
                                if (row.orderStatus == "WaitingPay")
                                    str += "<a class='btn btn-success btn-xs bt_pay btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' orderId=" + row.orderId + " totalPrice=" + row.totalPrice + "><i class='fa fa-pencil-square-o'></i>支付</a>";
                            }
                            if (row.orderStatus != "WaitingSign") {
                                str += "<a class='btn btn-success btn-xs bt_editAddress btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' id=" + row.id + " orderId=" + row.orderId + "><i class='fa fa-pencil-square-o'></i>修改地址</a>";
                            }
                            str += "<a class='btn btn-success btn-xs bt_editUserRemark btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' id=" + row.id + " orderId=" + row.orderId + "  userRemark="+row.userRemark+"><i class='fa fa-pencil-square-o'></i>修改备注</a>";
                            if (row.orderStatus == "WaitingSend" || row.orderStatus == "WaitingSign" || row.orderStatus == "TradeSuccess")
                                str += "<a class='btn btn-success btn-xs bt_send btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' pid=" + row.orderId + " ><i class='fa fa-pencil-square-o'></i>发货</a>";

                            return str;
                        }
                    }]

            });

            $mainDataTable = $("#db_Order_list").dataTable(dtSetting);
        };

        var exportOrder = function () {
            var url = $(this).attr("url");

            var startDate = $("input[name=startDate]").val();
            var endDate = $("input[name=endDate]").val();
            startDate = new Date(startDate);
            endDate = new Date(endDate);
            startDate.setDate(startDate.getDate() + 90);
            if (startDate.valueOf() < endDate.valueOf()) {
                $.alert("选择的日期区间过大,请减小区间多次导出");
                return false;
            }
            $("#form_Order").attr("action", url);
            $("#form_Order").submit();

        };
        var exportSkuOrder = function () {
            $("#exportSku_config").modal("show");
            $("#exportSku_config").find(".bt-save").unbind("click").bind("click", function () {
                var productName = $("#exportSku_config").find("[name=productIds]").val()
                if (productName != "") {
                    $("#exportSku_config").find("form").submit();
                    $("#exportSku_config").modal("hide");
                } else {
                    $.alert("请输入商品ID")
                    return false;
                }
            });
        }
        var updateSupplier = function () {
            loadSupplier(function (option) {
                $("#updateSupplier_Config").find("[name=supplierId]").empty().append(option)
                    .select2();
            });
            $("#updateSupplier_Config").modal("show");
            $("#updateSupplier_Config").find(".bt-save").unbind("click").bind("click", function () {
                var productIds = $("#updateSupplier_Config").find("[name=productIds]").val()
                var supplierId = $("#updateSupplier_Config").find("[name=supplierId]").val()
                if (supplierId == "" || supplierId == 1) {
                    $.alert("请输入选择商家")
                    return false;
                }
                if (productIds == "") {
                    $.alert("请输入商品ID")
                    return false;
                }

                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/updateOrderSupplierId.do",
                    data: {productIds: productIds, supplierId: supplierId},
                    async: true,
                    success: function (result) {
                        $("#updateSupplier_Config").modal("hide");
                    }
                });

            });
        }
        var pushSupplierOrder = function () {
            loadSupplier(function (option) {
                $("#pushSupplierOrderConfig").find("[name=supplierId]").empty().append(option)
                    .select2();
            });
            $("#pushSupplierOrderConfig").modal("show");
            $("#pushSupplierOrderConfig").find(".bt-save").unbind("click").bind("click", function () {
                var supplierId = $("#pushSupplierOrderConfig").find("[name=supplierId]").val()

                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/pushUnSendOrderToWdtBySupplierId.do",
                    data: {supplierId: supplierId},
                    async: true,
                    success: function (result) {
                        if (result.type == "success") {
                            $("#pushSupplierOrderConfig").modal("hide");
                        } else {
                            $.alert(result.content);
                        }
                    }
                });

            });
        }
        var batchSubmit = function () {
            $.confirm("你确认需要同步订单吗?", function () {
                $("#db_Order_list tbody tr").each(function (index, item) {
                    if ($(item).find(".userName").html() == "13800138000" || $(item).find(".userName").html() == "13800138001") {
                        var orderId = $(item).find(".orderId").html()
                        $.ajax({
                            type: "get",
                            url: App.getContextPath() + "admin/order/syncOrder.do",
                            data: {orderId: orderId},
                            async: true,
                            success: function (result) {

                            }
                        });
                    }
                })
            })

        }
        var editAddress = function () {
            var orderId = $(this).attr("orderId");
            var id = $(this).attr("id");
            $("#update_address_config").find(".orderId").html(orderId);
            $("#update_address_config").modal("show");
            $("#update_address_config").find(".bt-save").off("click").on("click", function () {
                var add = $("#update_address_config").find("[name=address]").val().split(",");
                if (add.length != 6) {
                    $.alert("输入的格式不正确")
                    return;
                }
                var order = {};
                order.id = id;
                order.receiver = add[0];
                order.telPhone = add[1];
                order.provinceName = add[2];
                order.cityName = add[3];
                order.areaName = add[4];
                order.address = add[5];
                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/updateAddress.do",
                    data: {order: JSON.stringify(order)},
                    async: true,
                    success: function (result) {
                        $.alert(result.content);
                        $("#update_address_config").modal("hide");
                    }
                });

            });
        }
        var editUserRemark = function () {
            var orderId = $(this).attr("orderId");
            var userRemark = $(this).attr("userRemark");
            $("#update_user_remark_config").find("[name=userRemark]").val(userRemark);
            $("#update_user_remark_config").find(".orderId").html(orderId);
            $("#update_user_remark_config").modal("show");
            $("#update_user_remark_config").find(".bt-save").off("click").on("click", function () {
                var userRemark = $("#update_user_remark_config").find("[name=userRemark]").val();
                if (userRemark == "") {
                    $.alert("请输入备注")
                    return;
                }
                var order = {};
                order.orderId = orderId;
                order.userRemark = userRemark;
                $.ajax({
                    type: "get",
                    url: App.getContextPath() + "admin/order/updateUserRemark.do",
                    data: order,
                    async: true,
                    success: function (result) {
                        $.alert(result.content);
                        if(result.type="success"){
                            searchOrder();
                            $("#update_user_remark_config").modal("hide");
                        }
                    }
                });

            });
        }


        return {
            init: function () {
                $("[name=validOrder]").prop("checked", true)
                $.initDate($("#form_Order"), 0, 0);
                $("#status_select").select2({placeholder: "选择状态"});
                $("#platform_select").select2({placeholder: "选择平台"});
                $("[name=orderType]").select2({placeholder: "选择类型"});
                $(".search").click(searchOrder);
                searchOrder();
                $(".export,.exportLogistics").click(exportOrder);
                $(".exportSkuOrder").click(exportSkuOrder);
                $(".updateSupplier").click(updateSupplier)
                $(".pushSupplierOrder").click(pushSupplierOrder)
                $(".batchSubmit").click(batchSubmit);

                $("#db_Order_list").on("click", ".bt_send", sendOrder);
                $("#db_Order_list").on("click", ".bt_complete", completeOrder);
                $("#db_Order_list").on("click", ".bt_sync", syncOrder);
                $("#db_Order_list").on("click", ".bt_update_exp_price", updateExpPrice);
                $("#db_Order_list").on("click", ".bt_pay", payOrder);
                $("#db_Order_list").on("click", ".bt_editAddress", editAddress);
                $("#db_Order_list").on("click", ".bt_editUserRemark", editUserRemark);

                $(".settleLogisticsCode").click(function () {
                    $(".search").off("click");
                    $("#logistics_config").find("select").select2();
                    $("#logistics_config").find("[name=logisticsCode]").val("");
                    $("#logistics_config").modal("show");
                    $("#logistics_config").find(".bt-save").unbind("click").click(function () {
                        if ($("#logistics_config").find("[name=logisticsCode]").val() == "") {
                            $.alert("请输入物流单号");
                            return false;
                        }
                        $("#logistics_config").find("form").submit();
                        $(".search").click(searchOrder);
                        $("#logistics_config").modal("hide");

                    });
                    $("#logistics_config").find(".btn-default").unbind("click").click(function () {
                        $(".search").click(searchOrder);

                    });
                })
            }
        }
    }();

    $(function () {
        $("#header").load("../head.html");
        App.init(); //Initialise plugins and elements
        Order.init();
    });
</script>
<!-- /JAVASCRIPTS -->
</body>
</html>